package Thread;

import java.time.DayOfWeek;

public class Demo3 {
    public static int count = 0;
    public static Object locker = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                synchronized (locker) {
                    count++;
                }
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                synchronized (locker) {
                    count++;
                }
            }
        });
        //设置为守护线程 主线程结束进程结束
        t1.start();
        t2.start();
        System.out.printf("t1是否为守护线程:%s\n", t1.isDaemon());
        System.out.printf("t2是否为守护线程:%s\n", t2.isDaemon());
        System.out.println(count);//线程安全问题
    }


}
